var tocConfig = {
    url: 'http://templatephimsd.blogspot.com/',
    feedNum: 20,
    labelName: (window['location']['hash'] && window['location']['hash'] != '#0' && window['location']['hash'] != '#search') ? encodeURIComponent(window['location']['hash']['substr'](1)) : false,
    numChars: 300,
    thumbWidth: 70,
    navText: 'Xem th\xEAm',
    frontText: 'Bay l\xEAn \u0111\u1EA7u',
    noImage: 'http://1.bp.blogspot.com/-htG7vy9vIAA/Tp0KrMUdoWI/AAAAAAAABAU/e7XkFtErqsU/s1600/grey.gif',
    loading: '<span>Loading...</span>',
    searching: '<span>Searching...</span>',
    MonthNames: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
    noResult: 'No Result'
};

function getID(_0x444ex3) {
    return document['getElementById'](_0x444ex3);
};
var head = document['getElementsByTagName']('head')[0],
    tocContainer = getID('feedContainer'),
    feedNav = getID('feedNav'),
    orderByer = getID('orderFeedBy'),
    labelSorter = getID('labelSorter'),
    input = getID('postSearcher')['getElementsByTagName']('input')[0],
    resultDesc = getID('resultDesc'),
    nextPage, feedArchive, startPage = 0;

function cropFeed(_0x444exf, _0x444ex10) {
    var _0x444ex11 = _0x444exf['split']('<');
    for (var _0x444ex12 = 0; _0x444ex12 < _0x444ex11['length']; _0x444ex12++) {
        if (_0x444ex11[_0x444ex12]['indexOf']('>') != -1) {
            _0x444ex11[_0x444ex12] = _0x444ex11[_0x444ex12]['substring'](_0x444ex11[_0x444ex12]['indexOf']('>') + 1, _0x444ex11[_0x444ex12]['length']);
        };
    };
    _0x444ex11 = _0x444ex11['join'](' ');
    _0x444ex11 = _0x444ex11['substring'](0, _0x444ex10 - 1);
    return _0x444ex11;
};

function showLabels(_0x444ex10) {
    var _0x444ex14 = _0x444ex10['feed']['category'],
        _0x444exf = '';
    _0x444exf = '<select id=\'labelSorter\' onchange=\'changeSort(this.value);\'>';
    _0x444exf += '<option value=\'\' selected>CATEGORY</option>';
    for (var _0x444ex3 = 0; _0x444ex3 < _0x444ex14['length']; _0x444ex3++) {
        _0x444exf += '<option value=\'' + decodeURIComponent(_0x444ex14[_0x444ex3]['term']) + '\'>' + _0x444ex14[_0x444ex3]['term']['toUpperCase']() + '</option>';
    };
    _0x444exf += '</select>';
    labelSorter['innerHTML'] = _0x444exf;
};

function showFeedList(_0x444ex16) {
    var _0x444ex17 = _0x444ex16['feed']['entry'],
        _0x444ex18, _0x444ex19, _0x444ex1a, _0x444ex1b, _0x444ex12, _0x444ex1c, _0x444ex1d, _0x444ex1e, _0x444ex1f, _0x444ex20, _0x444ex10 = '';
    if (typeof (_0x444ex16['feed']['entry']) !== 'undefined') {
        for (var _0x444ex11 = 0; _0x444ex11 < tocConfig['feedNum']; _0x444ex11++) {
            _0x444ex18 = (_0x444ex17) ? _0x444ex17[_0x444ex11] : '';
            nextPage = '';
            if (_0x444ex11 == _0x444ex16['feed']['entry']['length']) {
                break;
            };
            _0x444ex19 = _0x444ex18['title']['$t'];
            for (var _0x444exf = 0; _0x444exf < _0x444ex18['link']['length']; _0x444exf++) {
                if (_0x444ex18['link'][_0x444exf]['rel'] == 'alternate') {
                    _0x444ex1a = _0x444ex18['link'][_0x444exf]['href'];
                    break;
                };
            };
            for (var _0x444ex3 = 0; _0x444ex3 < _0x444ex16['feed']['link']['length']; _0x444ex3++) {
                if (_0x444ex16['feed']['link'][_0x444ex3]['rel'] == 'next') {
                    nextPage = _0x444ex16['feed']['link'][_0x444ex3]['href'];
                };
            };
            for (var _0x444ex14 = 0; _0x444ex14 < _0x444ex18['link']['length']; _0x444ex14++) {
                if (_0x444ex18['link'][_0x444ex14]['rel'] == 'replies' && _0x444ex18['link'][_0x444ex14]['type'] == 'text/html') {
                    _0x444ex20 = _0x444ex18['link'][_0x444ex14]['title'];
                    break;
                };
            };
            if ('content' in _0x444ex18) {
                _0x444ex12 = _0x444ex18['content']['$t'];
            } else {
                if ('summary' in _0x444ex18) {
                    _0x444ex12 = _0x444ex18['summary']['$t'];
                } else {
                    _0x444ex12 = '';
                };
            }; if ('media$thumbnail' in _0x444ex18) {
                _0x444ex1b = _0x444ex18['media$thumbnail']['url']['replace'](/\/s[0-9]+\-c/, '/s' + tocConfig['thumbWidth'] + '-c');
            } else {
                _0x444ex1b = tocConfig['noImage']['replace'](/\/s[0-9]+\-c/, '/s' + tocConfig['thumbWidth'] + '-c');
            };
            postdate = _0x444ex18['published']['$t']['substring'](0, 10);
            _0x444ex1c = postdate['substring'](0, 4);
            _0x444ex1d = postdate['substring'](5, 7);
            _0x444ex1e = postdate['substring'](8, 10);
            _0x444ex1f = tocConfig['MonthNames'][parseInt(_0x444ex1d, 10) - 1];
            _0x444ex10 += '<li><div>';
            _0x444ex10 += '<a href=\'' + _0x444ex1a + '\' target=\'_blank\'><img style=\'float:left;width:' + tocConfig['thumbWidth'] + 'px;height:' + tocConfig['thumbWidth'] + 'px;margin-right:10px;\' src=\'' + _0x444ex1b + '\' alt=\'' + _0x444ex19 + '\' /></a>';
            _0x444ex10 += '<h2 style=\'font-size:14px;\'><a href=\'' + _0x444ex1a + '\' target=\'_blank\'>' + _0x444ex19 + '</a></div>';
            _0x444ex10 += '<div style=\'margin-top:5px;\'>' + cropFeed(_0x444ex12, tocConfig['numChars']) + '&hellip;<br style=\'clear:both;\'/></h2>';
            _0x444ex10 += 'on: <span>' + _0x444ex1e + '</span>/<span>' + _0x444ex1f + '</span>/<span>' + _0x444ex1c + '</span></div></div></li>';
        };
        if (input['value'] !== '' && window['location']['hash'] == '#search') {
            resultDesc['innerHTML'] = '<span>Search Result for Keyword <strong>&quot;' + input['value'] + '&quot;</strong></span>';
        } else {
            resultDesc['innerHTML'] = '';
        };
        feedContainer['innerHTML'] += _0x444ex10;
        if (nextPage) {
            if (window['location']['hash'] && window['location']['hash'] !== '#0') {
                _0x444ex10 = '<a href=\'javascript:initResult(2);\' class=\'next\'>' + tocConfig['navText'] + '</a>';
            } else {
                _0x444ex10 = '<a href=\'javascript:initResult(1);\' class=\'next\'>' + tocConfig['navText'] + '</a>';
            };
        } else {
            _0x444ex10 = '<a href=\'#table-outer\' onclick=\'jQuery(&apos;html, body&apos;).animate({scrollTop: jQuery(&apos;#table-outer&apos;).offset().top}, 1500); return false\' class=\'front\'>' + tocConfig['frontText'] + '</a>';
        };
        feedNav['innerHTML'] = _0x444ex10;
        input['value'] = '';
        labelSorter['getElementsByTagName']('select')[0]['removeAttribute']('disabled');
        orderByer['removeAttribute']('disabled');
    } else {
        feedContainer['innerHTML'] = '';
        alert(tocConfig['noResult']);
        feedNav['innerHTML'] = '<a href=\'?reload=true\'>' + tocConfig['frontText'] + '</a>';
        searchDesc['innerHTML'] = '';
    };
};

function initResult(_0x444ex14) {
    var _0x444ex3, _0x444ex10;
    if (_0x444ex14 == 1) {
        _0x444ex3 = nextPage['indexOf']('?');
        _0x444ex10 = nextPage['substring'](_0x444ex3);
    } else {
        if (_0x444ex14 == 2) {
            _0x444ex3 = nextPage['indexOf']('?');
            _0x444ex10 = nextPage['substring'](_0x444ex3)['replace'](/\?/, '/-/' + window['location']['hash']['substr'](1) + '?');
        } else {
            _0x444ex10 = '?start-index=1&max-results=' + tocConfig['feedNum'] + '&orderby=' + orderByer['value'] + '&alt=json-in-script';
        };
    };
    _0x444ex10 += '&callback=showFeedList';
    updateScript(_0x444ex10);
};

function removeScript() {
    var _0x444ex14 = getID('temporer-script');
    _0x444ex14['parentNode']['removeChild'](_0x444ex14);
};

function buildLabels() {
    var _0x444ex14 = document['createElement']('script');
    _0x444ex14['type'] = 'text/javascript';
    _0x444ex14['src'] = (tocConfig['url'] === '' ? window['location']['protocol'] + '//' + window['location']['host'] : tocConfig['url']) + '/feeds/posts/summary?max-results=0&alt=json-in-script&callback=showLabels';
    head['appendChild'](_0x444ex14);
};

function updateScript(_0x444ex3) {
    if (startPage == 1) {
        removeScript();
    };
    feedNav['innerHTML'] = tocConfig['loading'];
    if (tocConfig['labelName'] !== false) {
        feedArchive = (tocConfig['url'] === '' ? window['location']['protocol'] + '//' + window['location']['host'] : tocConfig['url']) + '/feeds/posts/summary/-/' + tocConfig['labelName'] + _0x444ex3;
    } else {
        feedArchive = (tocConfig['url'] === '' ? window['location']['protocol'] + '//' + window['location']['host'] : tocConfig['url']) + '/feeds/posts/summary' + _0x444ex3;
    };
    var _0x444ex14 = document['createElement']('script');
    _0x444ex14['type'] = 'text/javascript';
    _0x444ex14['src'] = feedArchive;
    _0x444ex14['id'] = 'temporer-script';
    head['appendChild'](_0x444ex14);
    startPage = 1;
};

function changeSort(_0x444ex10) {
    removeScript();
    tocContainer['innerHTML'] = '';
    feedNav['innerHTML'] = tocConfig['loading'];
    var _0x444ex3 = document['createElement']('script'),
        _0x444exf = labelSorter['getElementsByTagName']('select')[0],
        _0x444ex14 = (_0x444ex10 !== 0) ? '/-/' + _0x444ex10 : '';
    _0x444ex3['type'] = 'text/javascript';
    _0x444ex3['id'] = 'temporer-script';
    _0x444ex3['src'] = (tocConfig['url'] === '' ? window['location']['protocol'] + '//' + window['location']['host'] : tocConfig['url']) + '/feeds/posts/summary' + _0x444ex14 + '?alt=json-in-script&max-results=' + tocConfig['feedNum'] + '&orderby=' + orderByer['value'] + '&callback=showFeedList';
    head['appendChild'](_0x444ex3);
    _0x444exf['disabled'] = true;
    orderByer['disabled'] = true;
    window['location']['hash'] = _0x444ex10;
};

function searchPost() {
    removeScript();
    tocContainer['innerHTML'] = '';
    resultDesc['innerHTML'] = '';
    feedNav['innerHTML'] = tocConfig['searching'];
    var _0x444ex14 = document['createElement']('script');
    _0x444ex14['type'] = 'text/javascript';
    _0x444ex14['id'] = 'temporer-script';
    _0x444ex14['src'] = (tocConfig['url'] === '' ? window['location']['protocol'] + '//' + window['location']['host'] : tocConfig['url']) + '/feeds/posts/summary?alt=json-in-script&orderby=published&q=' + input['value'] + '&max-results=9999&callback=showFeedList';
    head['appendChild'](_0x444ex14);
    window['location']['hash'] = '#search';
    return false;
};
getID('postSearcher')['onsubmit'] = function () {
    return searchPost();
};
orderByer['onchange'] = function () {
    changeSort(0);
};
labelSorter['getElementsByTagName']('select')[0]['onchange'] = function () {
    changeSort(this['value']);
};
window['onload'] = function () {
    initResult(0);
    buildLabels();
    window['location']['hash'] = '#0';
};